package com.rrd.dw.mr.gzip.kafka;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.bairong.BairongPortraitPreds10Record;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/*
 * 百融客制化评分2贷中联合建模
 *
 * @author:szw
 * */

public class BairongPortraitPreds10RecordParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * @param context
     * @param model
     * @param successful
     * @return
     * @throws IOException
     * @throws InterruptedException
     */

    @Override
    public boolean parseJob(Mapper.Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        BairongPortraitPreds10Record brpRecord = (BairongPortraitPreds10Record) model;
        JSONObject brpData = brpRecord.getData() == null ? new JSONObject() : JSON.parseObject(brpRecord.getData());

        StringBuilder sb = getBaseInfo(brpRecord, successful);
        StringBuilder brSb = new StringBuilder(500);

        // code
        brSb.append(brpData.getString("code") == null ? "" : brpData.getString("code")).append(CRT001);
        // swift_number
        brSb.append(brpData.getString("swift_number") == null ? "" : brpData.getString("swift_number")).append(CRT001);
        // flag_score
        brSb.append(brpData.getString("flag_score") == null ? "" : brpData.getString("flag_score")).append(CRT001);
        // flag_scoredata
        brSb.append(brpData.getString("flag_scoredata") == null ? "" : brpData.getString("flag_scoredata")).append(CRT001);
        // scorecust2
        brSb.append(brpData.getString("scorecust2") == null ? "" : brpData.getString("scorecust2")).append(CRT001);
        // sd_scorecust2_alf_apirisk_all_mean
        brSb.append(brpData.getString("sd_scorecust2_alf_apirisk_all_mean") == null ? "" : brpData.getString("sd_scorecust2_alf_apirisk_all_mean")).append(CRT001);
        // sd_scorecust2_alf_apirisk_all_sum
        brSb.append(brpData.getString("sd_scorecust2_alf_apirisk_all_sum") == null ? "" : brpData.getString("sd_scorecust2_alf_apirisk_all_sum")).append(CRT001);
        // sd_scorecust2_alf_apirisk_d30_sum
        brSb.append(brpData.getString("sd_scorecust2_alf_apirisk_d30_sum") == null ? "" : brpData.getString("sd_scorecust2_alf_apirisk_d30_sum")).append(CRT001);
        // sd_scorecust2_alf_apirisk_time_area_all_sum
        brSb.append(brpData.getString("sd_scorecust2_alf_apirisk_time_area_all_sum") == null ? "" : brpData.getString("sd_scorecust2_alf_apirisk_time_area_all_sum")).append(CRT001);
        // sd_scorecust2_alf_apirisk_time_lenth_all_mean
        brSb.append(brpData.getString("sd_scorecust2_alf_apirisk_time_lenth_all_mean") == null ? "" : brpData.getString("sd_scorecust2_alf_apirisk_time_lenth_all_mean")).append(CRT001);
        // sd_scorecust2_alf_apirisk_time_lenth_d30_mean
        brSb.append(brpData.getString("sd_scorecust2_alf_apirisk_time_lenth_d30_mean") == null ? "" : brpData.getString("sd_scorecust2_alf_apirisk_time_lenth_d30_mean")).append(CRT001);
        // sd_scorecust2_alf_apirisk_time_lenth_d90_mean
        brSb.append(brpData.getString("sd_scorecust2_alf_apirisk_time_lenth_d90_mean") == null ? "" : brpData.getString("sd_scorecust2_alf_apirisk_time_lenth_d90_mean")).append(CRT001);
        // sd_scorecust2_alf_apirisk_time_slope_d15_sum
        brSb.append(brpData.getString("sd_scorecust2_alf_apirisk_time_slope_d15_sum") == null ? "" : brpData.getString("sd_scorecust2_alf_apirisk_time_slope_d15_sum")).append(CRT001);
        // sd_scorecust2_alf_count_id
        brSb.append(brpData.getString("sd_scorecust2_alf_count_id") == null ? "" : brpData.getString("sd_scorecust2_alf_count_id")).append(CRT001);
        // sd_scorecust2_gl_m12_max_group_num
        brSb.append(brpData.getString("sd_scorecust2_gl_m12_max_group_num") == null ? "" : brpData.getString("sd_scorecust2_gl_m12_max_group_num")).append(CRT001);
        // sd_scorecust2_gl_m12_mean_group_num
        brSb.append(brpData.getString("sd_scorecust2_gl_m12_mean_group_num") == null ? "" : brpData.getString("sd_scorecust2_gl_m12_mean_group_num")).append(CRT001);
        // sd_scorecust2_gl_m12_mean_list_level
        brSb.append(brpData.getString("sd_scorecust2_gl_m12_mean_list_level") == null ? "" : brpData.getString("sd_scorecust2_gl_m12_mean_list_level")).append(CRT001);
        // sd_scorecust2_gl_m6_mean_list_level
        brSb.append(brpData.getString("sd_scorecust2_gl_m6_mean_list_level") == null ? "" : brpData.getString("sd_scorecust2_gl_m6_mean_list_level")).append(CRT001);
        // sd_scorecust2_ir_id_x_mail_cnt
        brSb.append(brpData.getString("sd_scorecust2_ir_id_x_mail_cnt") == null ? "" : brpData.getString("sd_scorecust2_ir_id_x_mail_cnt")).append(CRT001);
        // sd_scorecust2_ir_id_x_cell_cnt
        brSb.append(brpData.getString("sd_scorecust2_ir_id_x_cell_cnt") == null ? "" : brpData.getString("sd_scorecust2_ir_id_x_cell_cnt")).append(CRT001);
        key.set(getKey());
        val.set((sb.toString() + brSb.toString()).replace("\n", " ").replace("\r", " "));
        context.write(key, val);

        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_br_portrait_preds10_record_inc";
    }

    @Override
    public String getType() {
        return RecordType.BAIRONG_PORTRAIT_PREDS10_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "百融客制化评分2贷中联合建模";
    }
}
